package com.itcast.demo.entity;

/**
 * 二叉树类
 *
 * @author zheng.zhang
 */
public class BinaryTree {
    /**
     * 根节点
     */
    public TreeNode root;

    public BinaryTree () {
        this.root = new TreeNode(0);
    }

    /**
     * 构建二叉树
     *
     * @param treeNodes 节点数据集合
     */
    public void createBinaryTree(int[] treeNodes) {
        if (treeNodes == null || treeNodes.length == 0) {
            return;
        }
        TreeNode temp = root;
        int index = treeNodes.length - 1;
        while (index >= 0) {
            temp.left = new TreeNode(treeNodes[index--]);
            temp.right = new TreeNode(treeNodes[index--]);
        }
    }
}
